from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.cluster import KMeans

# 示例网页内容
documents = [
    "Machine learning is a subset of artificial intelligence.",
    "Deep learning uses neural networks for complex tasks.",
    "K-means is a popular clustering algorithm.",
    "Natural language processing involves text analysis.",
    "Neural networks are used in deep learning models."
]

# 将文本转换为TF-IDF向量
vectorizer = TfidfVectorizer(stop_words='english')
X = vectorizer.fit_transform(documents)

# 执行聚类
kmeans = KMeans(n_clusters=2, random_state=42)
clusters = kmeans.fit_predict(X)

# 输出聚类结果
for i, doc in enumerate(documents):
    print(i)
    print(" ")
    print(clusters[i])
    print(" ")
    print(doc)
    print("\n")